package com.lxy.user.api;

import cn.hutool.json.JSONUtil;
import com.lxy.common.JsonResult;
import com.lxy.user.service.LagouTokenService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 123
 * @date 2020/6/28 16:01
 * @description
 */
@RestController
@RequestMapping("user")
public class LagouTokenApi {


    @Autowired
    private LagouTokenService lagouTokenService;

    @PostMapping("register/{email}/{password}/{code}")
    public JsonResult register(@PathVariable String email,@PathVariable String password,@PathVariable String code) {
      return   lagouTokenService.register(email, password, code);
    }

    @GetMapping("isRegistered/{email}")
    public JsonResult isRegistered(@PathVariable String email) {
        Boolean bool = lagouTokenService.isRegistered(email);
        return JsonResult.ok(bool);
    }

    @PostMapping("login/{email}/{password}")
    public JsonResult login(@PathVariable String email, @PathVariable String password) {
        return lagouTokenService.login(email, password);
    }


    @GetMapping("info/{token}")
    public String authToken(@PathVariable String token) {
        return JSONUtil.toJsonStr(lagouTokenService.authToken(token));
    }


}
